import { Navigate, useLocation } from "react-router-dom"
import useGlobal from "renderer/hooks/useGlobal"

interface RequireAuthProps {
  children: JSX.Element
}


export default function RequireAuth(props: RequireAuthProps) {

  const { user } = useGlobal()
  const location = useLocation()

  // console.log('RequireAuth render =', user)

  if(user.token === '' || user.infoToken === '') {
    return <Navigate to="/login" state={{from: location}} replace />
  }

  return props.children
}
